import HTTP from '../utils/http';
import { API } from '../config/config';
import { Message } from 'element-ui';
import { axiosMessageShow, findAssign } from '@/utils/tools';
const ESSAY = API.ESSAY;
export default class EssayClass extends HTTP {
    findEssay(data) {
        return new Promise((resolve) => {
            this.axiosPost({
                url: ESSAY.ESSAY_GET,
                data,
                success(data) {
                    axiosMessageShow(data);
                    resolve(data.data)
                }, error(error) {
                    Message({
                        message: error,
                        type: 'error'
                    })
                }
            })
        })
    }
    findEssayAll() {
        return new Promise((resolve) => {
            this.axiosGet({
                url: ESSAY.ESSAY_GET_ALL,
                success(data) {

                    resolve(data.data)
                }, error(error) {
                    Message({
                        message: error,
                        type: 'error'
                    })
                }
            })
        })
    }
    findEssayCount() {
        return new Promise((resolve) => {
            this.axiosGet({
                url: ESSAY.ESSAY_GET_COUNT,
                success(data) {

                    resolve(data.data)
                }, error(error) {
                    Message({
                        message: error,
                        type: 'error'
                    })
                }
            })
        })
    }
    findEssayAssign(params) {
        const { title, type } = params;
        let data = findAssign(title, type)
        if (!data) {
            Message({
                message: "查询失败！",
                type: 'error'
            })
        }
        Message({
            message: "查询成功！",
            type: 'success'
        })
        return data;
    }
    destroyEssay(id) {
        return new Promise((resolve) => {
            this.axiosPost({
                url: ESSAY.ESSAY_DESTROY,
                data: id,
                success(data) {
                    axiosMessageShow(data);
                    resolve(data)
                }, error(error) {
                    Message({
                        message: error,
                        type: 'error'
                    })
                }
            })
        })
    }
    changeEssayStatus(data) {
        return new Promise((resolve) => {
            this.axiosPost({
                url: ESSAY.ESSAY_CHANGE_STATUS,
                data: data,
                success(data) {
                    axiosMessageShow(data);
                    resolve(data)
                }, error(error) {
                    Message({
                        message: error,
                        type: 'error'
                    })
                }
            })
        })
    }
    createEssay(data) {
        return new Promise((resolve) => {
            this.axiosPostFromdata({
                url: ESSAY.ESSAY_CREATE,
                data,
                success(data) {
                    axiosMessageShow(data);
                    resolve(data)
                }, error(error) {
                    Message({
                        message: error,
                        type: 'error'
                    })
                }
            })
        })
    }
    updateEssay(data) {
        return new Promise((resolve) => {
            this.axiosPostFromdata({
                url: ESSAY.ESSAY_UPDATE,
                data,
                success(data) {
                    axiosMessageShow(data);
                    resolve(data)
                }, error(error) {
                    Message({
                        message: error,
                        type: 'error'
                    })
                }
            })
        })
    }


}